#include <vector>

using namespace std;

class Solution {
public:
    int hIndex(vector<int>& citations) {
        if (citations.size() == 0) {
            return 0;
        }
        int ans = 0;
        for (int i = 0; i < citations.size(); i++) {
            ans = max(ans, min((int) citations.size() - i, citations[i]));
        }
        return ans;
    }
};